var mslibrary = require('ms-common-library');

var path = require('path');
var getmatchs = function (str, Regexp) {
    var i = 0;
    var list = [];





    while (str.substr(i, str.length).match(Regexp)) {
        var obj = str.substr(i, str.length).match(Regexp)
        i = i + obj.index + 1;
        list.push(obj[1]);
    }
    return list;
}
var jsfile=path.join(__dirname, './install.json');
mslibrary.openjson(jsfile, function (error, val) {

    var str = JSON.stringify(val);

    var list = getmatchs(str, new RegExp(/"Coinkey"[\s\S]+?(\w+)[\s\S]+?/i));

    var _list = getmatchs(str, new RegExp(/"parent"[\s\S]+?(\w+)[\s\S]+?/i));

    list = list.concat(_list);

    _list = getmatchs(str, new RegExp(/"model_id"[\s\S]+?(\w+)[\s\S]+?/i));

    list = list.concat(_list);
    for (let i = 0; i < list.length; i++) {
        const id = list[i];
        var key = mslibrary.MD5(id);
        str = str.replace('"' + id + '"', '"' + key + '"');
    }

    mslibrary.savefile(jsfile,str,function(){


    
    })
 

})